package com.zty.xiaomiadmin.server.Service.IndexService;

import com.zty.xiaomiadmin.server.Dao.Good;
import com.zty.xiaomiadmin.server.Dao.IndexMapper;
import com.zty.xiaomiadmin.server.utils.SqlSessionUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Service
public class IndexServiceImpl implements IndexService {

    @Override
    public Map<String, Object> getIndexData() throws IOException {
        Map<String, Object> map = new HashMap<>();
        int userNumber = SqlSessionUtil.getSqlSessionInstance().getSqlSession().getMapper(IndexMapper.class).getUserNumber();
        int orderNumber = SqlSessionUtil.getSqlSessionInstance().getSqlSession().getMapper(IndexMapper.class).getOrderNumber();
        int goodNumber = SqlSessionUtil.getSqlSessionInstance().getSqlSession().getMapper(IndexMapper.class).getGoodsNumber();
        map.put("userNumber", userNumber);
        map.put("orderNumber", orderNumber);
        map.put("goodNumber", goodNumber);
        return map;
    }

    @Override
    public Map<String, Object> getStoreIdByName(String name) throws IOException {
        Map<String, Object> map = new HashMap<>();
        String store_id = SqlSessionUtil.getSqlSessionInstance().getSqlSession().getMapper(IndexMapper.class).getStoreIdByName(name);
        map.put("store_id", store_id);
        return map;
    }
}
